/*	
	
	Copyright (c) 2007-2009 Ryan Christiansen
	
	This software is provided 'as-is', without any express or implied
	warranty. In no event will the authors be held liable for any damages
	arising from the use of this software.
	
	Permission is granted to anyone to use this software for any purpose,
	including commercial applications, and to alter it and redistribute it
	freely, subject to the following restrictions:
	
	1. The origin of this software must not be misrepresented; you must not
	claim that you wrote the original software. If you use this software
	in a product, an acknowledgment in the product documentation would be
	appreciated but is not required.
	
	2. Altered source versions must be plainly marked as such, and must not be
	misrepresented as being the original software.
	
	3. This notice may not be removed or altered from any source
	distribution.
	
*/
package funit.framework
{
	import funit.MessageValidator;
	
	[TestFixture]
	public class ArrayAssertTests extends MessageValidator
	{
		
		
		public function ArrayAssertTests()
		{
			
		}
		
		
		[Test]
		public function itemsOfType() : void
		{
			var array:Array = new Array( "x", "y", "z" );
			
			CollectionAssert.allItemsAreInstancesOf(array, String);
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function itemsOfTypeFailure() : void
		{
			var array:Array = new Array( "x", "y", new Object() );
			
			expectedMessage =
				"  Expected: all items instance of <String>" + MessageString.NewLine +
				"  But was:  [ \"x\", \"y\", <Object> ]" + MessageString.NewLine;
			
			CollectionAssert.allItemsAreInstancesOf(array, String);
		}
		
		[Test]
		public function itemsNotNull() : void
		{
			var array:Array = new Array( "x", "y", "z" );
			
			CollectionAssert.allItemsAreNotNull(array);
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function itemsNotNullFailure() : void
		{
			var array:Array = new Array( "x", null, "z" );
			
			expectedMessage =
				"  Expected: all items not null" + MessageString.NewLine +
				"  But was:  [ \"x\", null, \"z\" ]" + MessageString.NewLine;
			
			CollectionAssert.allItemsAreNotNull(array);
		}
		
		[Test]
		public function itemsUniqueObjects() : void
		{
			CollectionAssert.allItemsAreUnique(
				new Array( new Object(), new Object(), new Object() )
			);
		}
		
		[Test]
		public function itemsUniqueStrings() : void
		{
			CollectionAssert.allItemsAreUnique(
				new Array( "x", "y", "z" )
			);
		}
		
		[Test]
		public function itemsUniqueHandlesNull() : void
		{
			CollectionAssert.allItemsAreUnique(
				new Array( "x", "y", null, "z" )
			);
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function itemsUniqueFailure() : void
		{
			expectedMessage =
				"  Expected: all items unique" + MessageString.NewLine +
				"  But was:  [ \"x\", \"y\", \"x\" ]" + MessageString.NewLine;
			
			CollectionAssert.allItemsAreUnique( new Array( "x", "y", "x" ) );
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function itemsUniqueFailureOnTwoNulls() : void
		{
			expectedMessage =
				"  Expected: all items unique" + MessageString.NewLine +
				"  But was:  [ \"x\", null, \"y\", null, \"z\" ]" + MessageString.NewLine;
			
			CollectionAssert.allItemsAreUnique( new Array( "x", null, "y", null, "z" ) );
		}
		
		[Test]
		public function contains() : void
		{
			var array:Array = new Array( "x", "y", "z" );
			
			CollectionAssert.contains(array, "x");
		}
		
		[Test]
		public function containsNull() : void
		{
			var array:Array = [ 1, 2, 3, null, 4, 5 ];
			
			CollectionAssert.contains(array, null);
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function containsFailure() : void
		{
			var array:Array = new Array( "x", "y", "z" );
			
			expectedMessage =
				"  Expected: collection containing \"a\"" + MessageString.NewLine +
				"  But was:  [ \"x\", \"y\", \"z\" ]" + MessageString.NewLine;
			
			CollectionAssert.contains(array, "a");
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function containsFailureOnEmpty() : void
		{
			var array:Array = new Array();
			
			expectedMessage =
				"  Expected: collection containing \"x\"" + MessageString.NewLine +
				"  But was:  <empty>" + MessageString.NewLine;
			
			CollectionAssert.contains(array, "x");
		}
		
		[Test]
		public function doesNotContain() : void
		{
			var array:Array = new Array( "x", "y", "z" );
			
			CollectionAssert.doesNotContain(array, "a");
		}
		
		[Test]
		public function doesNotContainOnEmpty() : void
		{
			var array:Array = new Array();
			
			CollectionAssert.doesNotContain(array, "x");
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function doesNotContainFailure() : void
		{
			var array:Array = new Array( "x", "y", "z" );
			
			expectedMessage =
				"  Expected: collection not containing \"y\"" + MessageString.NewLine +
				"  But was:  [ \"x\", \"y\", \"z\" ]" + MessageString.NewLine;
			
			CollectionAssert.doesNotContain(array, "y");
		}
		
		[Test]
		public function isEmpty() : void
		{
			var array:Array = new Array();
			
			CollectionAssert.isEmpty( array, "Failed on empty Array" );
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function isEmptyFailure() : void
		{
			var array:Array = new Array( "x", "y", "z" );
			
			expectedMessage =
				"  Expected: <empty>" + MessageString.NewLine +
				"  But was:  [ \"x\", \"y\", \"z\" ]" + MessageString.NewLine;
			
			CollectionAssert.isEmpty(array);
		}
		
		[Test]
		public function isNotEmpty() : void
		{
			var array:Array = new Array( "x", "y", "z" );
			
			CollectionAssert.isNotEmpty( array, "Failed on Array" );
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function isNotEmptyFailure() : void
		{
			var array:Array = new Array();
			
			expectedMessage =
				"  Expected: not <empty>" + MessageString.NewLine +
				"  But was:  <empty>" + MessageString.NewLine;
			
			CollectionAssert.isNotEmpty(array);
		}
		
		[Test]
		public function areEqual() : void
		{
			var set1:Array = new Array( "x", "y", "z" );
			var set2:Array = new Array( "x", "y", "z" );
			
			CollectionAssert.areEqual(set1, set2);
		}
		
		[Test]
		public function areEqualHandlesNull() : void
		{
			var set1:Array = [ null, null, null ];
			var set2:Array = [ null, null, null ];
			
			CollectionAssert.areEqual(set1, set2);
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function areEqualFailure() : void
		{
			var set1:Array = new Array( "x", "y", "z" );
			var set2:Array = new Array( "x", "y", "a" );
			
			expectedMessage =
				"  Expected and actual are both <Array> with 3 elements" + MessageString.NewLine +
				"  Values differ at index [2]" + MessageString.NewLine +
				"  String lengths are both 1. Strings differ at index 0." + MessageString.NewLine +
				"  Expected: \"z\"" + MessageString.NewLine +
				"  But was:  \"a\"" + MessageString.NewLine +
				"  -----------^" + MessageString.NewLine;
			
			CollectionAssert.areEqual(set1, set2);
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function areEqualFailureOnLength() : void
		{
			var set1:Array = new Array( "x", "y", "z" );
			var set2:Array = new Array( "x", "y", "z", "a" );
			
			expectedMessage =
				"  Expected is <Array> with 3 elements, actual is <Array> with 4 elements" + MessageString.NewLine +
				"  Values differ at index [3]" + MessageString.NewLine +
				"  Extra:    [ \"a\" ]" + MessageString.NewLine;
			
			CollectionAssert.areEqual(set1, set2);
		}
		
		[Test]
		public function areNotEqual() : void
		{
			var set1:Array = new Array( "x", "y", "z" );
			var set2:Array = new Array( "x", "y", "a" );
			
			CollectionAssert.areNotEqual(set1, set2);
		}
		
		[Test]
		public function areNotEqualHandlesNull() : void
		{
			var set1:Array = [ null, "y", null ];
			var set2:Array = [ "x", "y", "z" ];
			
			CollectionAssert.areNotEqual(set1, set2);
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function areNotEqualFailure() : void
		{
			var set1:Array = new Array( "x", "y", "z" );
			var set2:Array = new Array( "x", "y", "z" );
			
			expectedMessage =
				"  Expected: not [ \"x\", \"y\", \"z\" ]" + MessageString.NewLine +
				"  But was:  [ \"x\", \"y\", \"z\" ]" + MessageString.NewLine;
			
			CollectionAssert.areNotEqual(set1, set2);
		}
		
		[Test]
		public function areEquivalent() : void
		{
			var set1:Array = new Array( "x", "y", "z" );
			var set2:Array = new Array( "z", "y", "x" );
			
			CollectionAssert.areEquivalent(set1, set2);
		}
		
		[Test]
		public function areEquivalentHandlesNull() : void
		{
			var set1:Array = [null, "x", null, "z"];
			var set2:Array = ["z", null, "x", null];
			
			CollectionAssert.areEquivalent(set1, set2);
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function areEquivalentFailure() : void
		{
			var set1:Array = new Array( "x", "y", "z" );
			var set2:Array = new Array( "x", "y", "x" );
			
			expectedMessage =
				"  Expected: equivalent to [ \"x\", \"y\", \"z\" ]" + MessageString.NewLine +
				"  But was:  [ \"x\", \"y\", \"x\" ]" + MessageString.NewLine;
			
			CollectionAssert.areEquivalent(set1, set2);
		}
		
		[Test]
		public function areNotEquivalent() : void
		{
			var set1:Array = new Array( "x", "y", "z" );
			var set2:Array = new Array( "x", "y", "x" );
			
			CollectionAssert.areNotEquivalent(set1, set2);
		}
		
		[Test]
		public function areNotEquivalentHandlesNull() : void
		{
			var set1:Array = new Array( "x", null, "z" );
			var set2:Array = new Array( "x", null, "x" );
			
			CollectionAssert.areNotEquivalent(set1, set2);
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function areNotEquivalentFailure() : void
		{
			var set1:Array = new Array( "x", "y", "z" );
			var set2:Array = new Array( "x", "z", "y" );
			
			expectedMessage =
				"  Expected: not equivalent to [ \"x\", \"y\", \"z\" ]" + MessageString.NewLine +
				"  But was:  [ \"x\", \"z\", \"y\" ]" + MessageString.NewLine;
			
			CollectionAssert.areNotEquivalent(set1, set2);
		}
		
		[Test]
		public function isSubsetOf() : void
		{
			var subset:Array   = new Array( "y", "z" );
			var superset:Array = new Array( "x", "y", "z" );
			
			CollectionAssert.isSubsetOf(subset, superset);
		}
		
		[Test]
		public function isSubsetOfHandlesNull() : void
		{
			var subset:Array   = new Array( null, "z" );
			var superset:Array = new Array( "x", null, "z" );
			
			CollectionAssert.isSubsetOf(subset, superset);
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function isSubsetOfFailure() : void
		{
			var subset:Array   = new Array( "x", "y", "z" );
			var superset:Array = new Array( "y", "z", "a" );
			
			expectedMessage =
				"  Expected: subset of [ \"y\", \"z\", \"a\" ]" + MessageString.NewLine +
				"  But was:  [ \"x\", \"y\", \"z\" ]" + MessageString.NewLine;
			
			CollectionAssert.isSubsetOf(subset, superset);
		}
		
		[Test]
		public function isNotSubsetOf() : void
		{
			var subset:Array   = new Array( "x", "y", "z" );
			var superset:Array = new Array( "y", "z", "a" );
			
			CollectionAssert.isNotSubsetOf(subset, superset);
		}
		
		[Test]
		public function isNotSubsetOfHandlesNull() : void
		{
			var subset:Array   = new Array( "x", null, "z" );
			var superset:Array = new Array( null, "z", "a" );
			
			CollectionAssert.isNotSubsetOf(subset, superset);
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function isNotSubsetOfFailure() : void
		{
			var subset:Array   = new Array( "y", "z" );
			var superset:Array = new Array( "x", "y", "z" );
			
			expectedMessage =
				"  Expected: not subset of [ \"x\", \"y\", \"z\" ]" + MessageString.NewLine +
				"  But was:  [ \"y\", \"z\" ]" + MessageString.NewLine;
			
			CollectionAssert.isNotSubsetOf(subset, superset);
		}
		
	}
	
}